package com.tedu.m5;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/30
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory c = new ConnectionFactory();
        c.setHost("192.168.126.129");
        c.setPort(5672);
        c.setUsername("admin");
        c.setPassword("admin");
        Channel channel = c.newConnection().createChannel();
        channel.exchangeDeclare("topic_logs", BuiltinExchangeType.TOPIC);
        while (true){
            System.out.println("输入消息：");
            String msg = new Scanner(System.in).nextLine();
            System.out.println("输入路由：");
            String route = new Scanner(System.in).nextLine();
            channel.basicPublish("topic_logs", route, null, msg.getBytes());
        }

    }
}
